﻿package com.badibadi.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;
import com.amap.api.location.core.GeoPoint;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.AMap.OnMapClickListener;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.GeocodeSearch.OnGeocodeSearchListener;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.help.Inputtips;
import com.amap.api.services.help.Inputtips.InputtipsListener;
import com.amap.api.services.help.Tip;
import com.badibadi.adapter.AddingRecordNewAdapter;
import com.badibadi.adapter.AlbumAdapter;
import com.badibadi.infos.ClueTypeModel;
import com.badibadi.infos.ImageAttribute;
import com.badibadi.infos.MyFriendsModel;
import com.badibadi.infos.Results;
import com.badibadi.infos.imgs_Model;
import com.badibadi.infos.listType_Model;
import com.badibadi.mail.Mail15_huifuActivity;
import com.badibadi.maputil.AMapUtil;
import com.badibadi.maputil.ToastUtil;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.FriendsTool;
import com.badibadi.mytools.ImageTools;
import com.badibadi.mytools.InterestModel;
import com.badibadi.mytools.JSONUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.XUtils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;
import com.libjph.util.StringUtil;

import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

//3000 spinnder up_pictures_spinner up_pictures_spinner create_club_number2 create_club_number2 up_pictures_spinner
public class UpPictures3Activity extends BaseActivity implements
		// Nycgtjxxztup
		OnClickListener, LocationSource, AMapLocationListener,
		OnGeocodeSearchListener, TextWatcher, OnMapClickListener {

	private String TAG = "UpPictures3Activity";
	private String uid;
	private String pan = null, club = null, no_dou = null;
	private int picNumber = 0;
	private GridView mGridView;
	private AddingRecordNewAdapter arnAdapter;
	private Map<Integer, String> TitleMap;
	private ArrayList<String> strings, service_address;
	private EditText up_pictures_Source;
	private Spinner up_pictures_spinner;
	private List<ClueTypeModel> models;
	private AlbumAdapter albumadapter;
	private AutoCompleteTextView up_pictures_addfriends, up_pictures_describe;
	private ImageAttribute attribute;
	private CheckBox is_up_pictures_dongtai;
	private LinearLayout button_address;

	private LinearLayout ll;// 选择相簿的显示组件

	private Friend_Item_Adapter friend_Item_Adapter;
	private Gallery up_pictures_addfriends_list;
	private List<MyFriendsModel> listObj_main;
	// 下面是地图的
	private AMap aMap;
	private MapView mapView;
	private OnLocationChangedListener mListener;
	private LocationManagerProxy mAMapLocationManager;
	private GeoPoint geoPoint;
	private boolean isFirstCallBack = true;// 是否为第一次回调
	// 发源地
	private AutoCompleteTextView searchText;
	private ProgressDialog progDialog = null;
	private GeocodeSearch geocoderSearch;
	private Marker geoMarker;
	private Marker regeoMarker;
	private String temp_edit;
	private int upimgnum = 0;
	// 这里保存要上传的地址名
	private String addressName;
	// 这里保存要上传的经纬度
	private LatLonPoint latLonPoint = null;// new LatLonPoint(40.003662,
											// 116.465271)
	private List<InterestModel> Interestlist;
	private listType_Model listType_Model;
	private String photoid, activity_id;
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(UpPictures3Activity.this);
				Utils.showMessage(UpPictures3Activity.this, getResources()
						.getString(R.string.l_net_error));
				break;
			case 2:
				Utils.ExitPrgress(UpPictures3Activity.this);
				// Interestlist.clear();
				if (listType_Model != null && listType_Model.getLists() != null) {
					Interestlist.addAll(listType_Model.getLists());
//					   
				} else {
//					   
				}

				arnAdapter = new AddingRecordNewAdapter(
						UpPictures3Activity.this, Interestlist);
				mGridView.setAdapter(arnAdapter);
				//    ("标签总数量：" + Interestlist.size());
				attribute.setBiaoqian_num(Interestlist.size());
				Log.i(TAG, "biaoqian");
				// arnAdapter.notifyDataSetChanged();
				//    ("刷新成功");
				if (club != null) {
					user_photo_club();
				} else {
					user_photo();
				}
				break;
			case 3:
				Utils.ExitPrgress(UpPictures3Activity.this);
				Utils.showMessage(UpPictures3Activity.this, getResources()
						.getString(R.string.l_xa10));
				break;
			case 4:
				Utils.ExitPrgress(UpPictures3Activity.this);
				albumadapter = new AlbumAdapter(models, getApplicationContext());
				Log.i(TAG, "moxing");
				up_pictures_spinner.setAdapter(albumadapter);
				try {
					if (!models.isEmpty()) {
						for (int i = 0; i < models.size(); i++) {
							if (models.get(i).getId().equals(photoid)) {
								up_pictures_spinner.setSelection(i);
							}
						}
					}
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 2000:
				Utils.ExitProgress_hen(UpPictures3Activity.this);
				// Utils.ExitPrgress_Noclose(UpPictures3Activity.this);
				Utils.showMessage(UpPictures3Activity.this, getResources()
						.getString(R.string.l_xb18));
				String resultddd = msg.getData().getString("path");
				service_address.add(resultddd);
				attribute.setService_img_address(service_address);
//				   ("上传图片返回的结果是:" + resultddd);

				Intent intent = new Intent();
				intent.putExtra("img_info", attribute);
				setResult(5, intent);
				finish();
				// Message message = new Message();
				// Bundle bundle = new Bundle();
				// message.what = 3000;
				// bundle.putSerializable("img_info", attribute);
				// message.setData(bundle);
				// Constants.num_up_img_handler.sendMessage(message);
				UpPictures3Activity.this.finish();
				break;
			default:
				break;
			}
		}
	};

	private ArrayList<String> jiequ(String cond, String pand, String jia) {
		String[] ddd = cond.split(pand);
		ArrayList<String> strings = new ArrayList<String>();
		if (ddd.length > 1) {
			for (int i = 0; i < ddd.length; i++) {
				if (!StringUtil.isNullOrEmpty(ddd[i])) {
					String d = jia + ddd[i];
					strings.add(d);
				}
			}
		} else {
			strings.add(cond);
		}
		return strings;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.up_pictures3);
		uid = Utils.getUid(UpPictures3Activity.this);
		up_pictures_Source = (EditText) findViewById(R.id.up_pictures_Source);
		mapView = (MapView) findViewById(R.id.map);
		mapView.onCreate(savedInstanceState);// 此方法必须重写
		init();
		Log.i(TAG, "chushihua");
		Interest();
		Log.i(TAG, "xingqu");
	}

	
	
	private void init() {
		// TODO Auto-generated method stub
		attribute = new ImageAttribute();
		strings = getIntent().getStringArrayListExtra("files");
		try {
			pan = getIntent().getStringExtra("pan");
			club = getIntent().getStringExtra("club");
			no_dou = getIntent().getStringExtra("no_dou");
			photoid = getIntent().getStringExtra("photoid");
			activity_id = getIntent().getStringExtra("activity_id");
		} catch (Exception e) {
			pan = null;
		}
		service_address = new ArrayList<String>();
		if (strings != null && !strings.isEmpty()) {
			picNumber = strings.size();
		} else {
			picNumber = 0;
		}
		// attribute.setZhan_num(strings.size() + "");
		attribute.setArrayList(strings);
		TextView ts = (TextView) this.findViewById(R.id.up_pic3_tishi);
		is_up_pictures_dongtai = (CheckBox) findViewById(R.id.is_up_pictures_dongtai);
		ll = (LinearLayout) this.findViewById(R.id.ll);
		if (activity_id != null) {
			ll.setVisibility(View.GONE);
		} else {
			ll.setVisibility(View.VISIBLE);
		}
		String text = String.format(
				getResources().getString(R.string.Nycgtjxxztup), picNumber);
		SpannableStringBuilder style = new SpannableStringBuilder(text);
		int index = style.toString().indexOf("" + picNumber);
		// 设置指定位置文字的颜色
		style.setSpan(
				new ForegroundColorSpan(getResources().getColor(
						R.color.orange_fa7822)), index,
				(index + ("" + picNumber).length()),
				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
		ts.setText(style);
		listObj_main = new ArrayList<MyFriendsModel>();
		up_pictures_addfriends_list = (Gallery) findViewById(R.id.up_pictures_addfriends_list);
		friend_Item_Adapter = new Friend_Item_Adapter(UpPictures3Activity.this);
		up_pictures_addfriends_list.setAdapter(friend_Item_Adapter);
		button_address = (LinearLayout) findViewById(R.id.button_address);

		this.findViewById(R.id.up_pictures3_search_friends).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View arg0) {
						Intent intent = new Intent(UpPictures3Activity.this,
								MyFriendsResultActivity.class);
						startActivityForResult(intent, 3);
					}
				});
		this.findViewById(R.id.up_pictures_new_photos).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						Intent intent = new Intent(UpPictures3Activity.this,
								CreateNewPoly1Activity.class);
						startActivity(intent);
					}
				});
		up_pictures_describe = (AutoCompleteTextView) findViewById(R.id.up_pictures_describe);
		up_pictures_describe.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2,
					int arg3) {
				// TODO Auto-generated method stub

			}

			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,
					int arg2, int arg3) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable arg0) {
				attribute.setInfo(arg0.toString());
			}
		});
		attribute.setIs_displaydongtai("1");
		attribute.setIs_displaydongtai("0");
		// is_up_pictures_dongtai
		// .setOnCheckedChangeListener(new OnCheckedChangeListener() {
		// @Override
		// public void onCheckedChanged(CompoundButton arg0,
		// boolean arg1) {
		// if (arg1) {
		// attribute.setIs_displaydongtai("1");
		// } else {
		// attribute.setIs_displaydongtai("0");
		// }
		// }
		// });
		up_pictures_spinner = (Spinner) findViewById(R.id.up_pictures_spinner);
		mGridView = (GridView) findViewById(R.id.up_picture_gridView1);
		Interestlist = new ArrayList<InterestModel>();
		models = new ArrayList<ClueTypeModel>();
		this.findViewById(R.id.create_club_number2).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View arg0) {
						attribute.setCanyu_persons(FriendsTool.BackAllResult(
								"sdf", listObj_main));
						// attribute.setService_img_address(service_address);
						if (up_pictures_Source.getText().toString() != null) {
							attribute.setLaiyuan(up_pictures_Source.getText()
									.toString());
						}
						if (attribute.getAddress_jingdu() != null
								&& attribute.getAddress_weidu() != null) {
							if (attribute.getBiaoqian_map() != null) {// &&
																		// !attribute.getBiaoqian_map().isEmpty()
								if (attribute.getInfo() != null || true) {// attribute.getCanyu_persons()
																			// !=
																			// null
																			// &&
																			// attribute.getLaiyuan()
																			// !=
																			// null
									if (pan != null && pan.equals("douhao")) {
										if (no_dou != null) {
											// Utils.showPrgress(UpPictures3Activity.this);
//											   
											XUtils.UpImg_ceshi(strings,
													UpPictures3Activity.this,
													handler);

										} else {
											// Utils.showPrgress(UpPictures3Activity.this);
//											   
											// Utils.showMessage(UpPictures3Activity.this,
											// getResources().getString(R.string.l_xb46));
											XUtils.UpImg_ceshi_douhaoXUtils(
													strings,
													UpPictures3Activity.this,
													handler);
										}
									} else {
										// Utils.showPrgress(UpPictures3Activity.this);
										XUtils.UpImg_ceshi(strings,
												UpPictures3Activity.this,
												handler);
									}
								} else {
									Toast.makeText(
											getApplicationContext(),
											getResources().getString(
													R.string.l_xb26), 0).show();
								}
							} else {
								Toast.makeText(
										getApplicationContext(),
										getResources().getString(
												R.string.l_xb32), 0).show();
							}
						} else {
							Toast.makeText(getApplicationContext(),
									getResources().getString(R.string.l_xb146),
									0).show();
						}
					}
				});
		this.findViewById(R.id.up_pictures_back).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View arg0) {
						UpPictures3Activity.this.finish();
					}
				});
		up_pictures_spinner
				.setOnItemSelectedListener(new OnItemSelectedListener() {

					@Override
					public void onItemSelected(AdapterView<?> arg0, View arg1,
							int arg2, long arg3) {
						// TODO Auto-generated method stub
						// xiangceid = models.get(arg2).getId();
						attribute.setXiangceid(models.get(arg2).getId());
						Log.i(TAG, "xiala");
						// Toast.makeText(getApplicationContext(),
						// models.get(arg2).getId(), 0).show();
					}

					@Override
					public void onNothingSelected(AdapterView<?> arg0) {
						// TODO Auto-generated method stub

					}
				});

		mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long arg3) {
				// TODO Auto-generated method stub
				if (arnAdapter.getIsItemClick(position) == true) {
					arnAdapter.setIsItemClick(position);
					arnAdapter.notifyDataSetInvalidated();
				} else if (arnAdapter.getSelectNumber() >= arnAdapter
						.getUpperLimit()) {
					ShowToast(UpPictures3Activity.this,
							getResources().getString(R.string.l_xb4)
									+ arnAdapter.getUpperLimit()
									+ getResources().getString(R.string.l_xb5));
				} else {
					arnAdapter.setIsItemClick(position);
					arnAdapter.notifyDataSetInvalidated();
				}
				
				// 提交只需要提交TitleMap中的数据即可
				attribute.setBiaoqian_map(arnAdapter.getTitleMap());
//				   
			}
		});

		this.findViewById(R.id.up_pictures_dingwei).setOnClickListener(this);
		searchText = (AutoCompleteTextView) this.findViewById(R.id.fayuandi);
		searchText.addTextChangedListener(this);

		progDialog = new ProgressDialog(this);
		geocoderSearch = new GeocodeSearch(this);
		geocoderSearch.setOnGeocodeSearchListener(this);

		if (aMap == null) {
			aMap = mapView.getMap();

			geoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
					.icon(BitmapDescriptorFactory
							.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
			regeoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
					.icon(BitmapDescriptorFactory
							.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
			setUpMap();
		}
//		Interest();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		/**
		 * at好友
		 */
		if (requestCode == 3 && resultCode == 3) {
//			   ("进入");
			// et_sendDynamic.setText(et_sendDynamic.getText().toString()+data.getStringExtra("result"));
			List<MyFriendsModel> listObj = (ArrayList<MyFriendsModel>) data
					.getSerializableExtra("result");
			// for (int i = 0; i < listObj.size(); i++) {
			//    ("@好友数据:" + listObj.get(i).toString());
			// }
			for (int i = 0; i < listObj.size(); i++) {
				if (listObj.get(i).isJudge()) {
					listObj_main.add(listObj.get(i));
				}
			}
			if (listObj_main.size() > 0 && listObj_main.size() >= 3) {
				up_pictures_addfriends_list
						.setSelection(listObj_main.size() / 2 + 1);
			} else if (listObj_main.size() > 0 && listObj_main.size() == 2) {
				up_pictures_addfriends_list.setSelection(1);
			}
			friend_Item_Adapter.notifyDataSetChanged();
			//    ("我是回传数据" + listObj.get(0).getNickName());

		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	private void Interest() {
		Utils.showPrgress(UpPictures3Activity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				listType_Model = new listType_Model();
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("type", "jilu");
				map.put("languageType",
						Dialog.getSystemLanguageType(UpPictures3Activity.this));
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "type/listType");
				Log.i(TAG, "解析3");
//				   
				if (content != null) {
					//    ("结果是:" + content);
					Results results = Utils.checkResult_NNN(
							getApplicationContext(), content);
					if (results != null && results.getRetmsg() != null) {
//						   
						//    
						//    ("得到的结果是：" + results.getRetmsg());
						try {
							listType_Model = JSONUtils.getEntityByJsonString(
									results.getRetmsg(), listType_Model.class);
							System.out.println("Interest"+results.getRetmsg());
							Log.i(TAG, "解析jieguo3");
							handler.sendEmptyMessage(2);
						} catch (Exception e) {
							// TODO Auto-generated catch block
//							   
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void user_photo() {
		Utils.showPrgress(UpPictures3Activity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				// Map<String, Object> map = new HashMap<String, Object>();
				// map.put("uid", "1");
				String content = Utils.getRequest(Constants.BadiUrl
						+ "user_photo?uid=" + uid);
				Log.i(TAG, "解析2");
				if (content != null) {
//					   
					Results results = Utils.checkResult_NNN(
							getApplicationContext(), content);
					if (results != null && results.getRetmsg() != null) {
//						   
						try {
							models = JSONUtils.getListByJsonString(
									results.getRetmsg(), ClueTypeModel.class);
							System.out.println("user_photo"+results.getRetmsg());
							Log.i(TAG, "解析jieguo2");
							handler.sendEmptyMessage(4);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void user_photo_club() {
		Utils.showPrgress(UpPictures3Activity.this);
		MyThreadTool.fixedThreadPool.execute(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("cid", club);
				String content = Utils.sendRequest(map, Constants.BadiUrl_1
						+ "club/photoList");
				Log.i(TAG, "解析");
				if (content != null) {
//					   ("俱乐部的聚乐版返回结果是:" + content);
					Results results = Utils.checkResult_NNN(
							getApplicationContext(), content);
					if (results != null && results.getRetmsg() != null) {
						//    ("得到的结果是：" + results.getRetmsg());
						try {
							models = JSONUtils.getListByJsonString(
									results.getRetmsg(), ClueTypeModel.class);
							System.out.println("user_photo_club"+results.getRetmsg());
							Log.i(TAG, "解析jieguo");
							handler.sendEmptyMessage(4);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	private void setUpMap() {
		// TODO Auto-generated method stub
		aMap.moveCamera(CameraUpdateFactory
				.newLatLngZoom(Constants.CHENGDU, 12));// 设置指定的可视区域地图
		// aMap.setMyLocationStyle(myLocationStyle);
		aMap.setOnMapClickListener(this);// 点击地图上的
		aMap.setLocationSource(this);// 设置定位监听
		aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
		aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onResume() {
		super.onResume();
		mapView.onResume();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onPause() {
		super.onPause();
		mapView.onPause();
		deactivate();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		mapView.onSaveInstanceState(outState);
	}

	/**
	 * 方法必须重写
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		mapView.onDestroy();
	}

	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub

	}

	// 点击地图的上东西后回调
	@Override
	public void onMapClick(LatLng latlng) {
		// TODO Auto-generated method stub
		if (aMap != null && latlng != null) {
			aMap.clear();
			// MarkerOptions markerOptions=new MarkerOptions();
			// markerOptions.

			geoMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
					.icon(BitmapDescriptorFactory
							.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
			// aMap.addMarker(new MarkerOptions());
			geoMarker.setPosition(latlng);
			getAddress(AMapUtil.convertToLatLonPoint(latlng));
			aMap.invalidate();
			latLonPoint = AMapUtil.convertToLatLonPoint(latlng);
//			   
//					"address+====>" + addressName + " latLonPoint--->"
//							+ latLonPoint.getLatitude() + ","
//							+ latLonPoint.getLongitude());

		}
	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub

	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub

	}

	// TextWatcher

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		// TODO Auto-generated method stub
		String newText = s.toString().trim();
		Inputtips inputTips = new Inputtips(UpPictures3Activity.this,
				new InputtipsListener() {

					@Override
					public void onGetInputtips(List<Tip> tipList, int rCode) {
						if (rCode == 0) {// 正确返回
							List<String> listString = new ArrayList<String>();
							for (int i = 0; i < tipList.size(); i++) {
								listString.add(tipList.get(i).getName());
							}
							ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
									getApplicationContext(),
									R.layout.route_inputs, listString);
							searchText.setAdapter(aAdapter);
							aAdapter.notifyDataSetChanged();
						}
					}
				});
		try {
			inputTips.requestInputtips(newText, null);// 第一个参数表示提示关键字，第二个参数默认代表全国，也可以为城市区号

		} catch (AMapException e) {
			   
		}
	}

	/**
	 * 地理编码查询回调
	 */
	@Override
	public void onGeocodeSearched(GeocodeResult result, int rCode) {
		// // TODO Auto-generated method stub
		dismissDialog();
		if (rCode == 0) {
			if (result != null && result.getGeocodeAddressList() != null
					&& result.getGeocodeAddressList().size() > 0) {
				GeocodeAddress address = result.getGeocodeAddressList().get(0);
				aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
						AMapUtil.convertToLatLng(address.getLatLonPoint()), 15));
				geoMarker.setPosition(AMapUtil.convertToLatLng(address
						.getLatLonPoint()));
				attribute.setAddress_weidu(address.getLatLonPoint()
						.getLatitude() + "");// 纬度
				attribute.setAddress_jingdu(address.getLatLonPoint()
						.getLongitude() + "");// 经度
				attribute.setCity_name(address.getCity());
				addressName = getResources().getString(R.string.l_xb97)
						+ address.getLatLonPoint() + "\n"
						+ getResources().getString(R.string.l_xb98)
						+ address.getFormatAddress();
				attribute.setAbsolute_address(address.getFormatAddress());// 获取地理位置
				// 这里保存要上传的经纬度
				latLonPoint = address.getLatLonPoint();
//				   
//						+ "///" + latLonPoint.getLongitude());

				ShowToast(UpPictures3Activity.this, addressName);
			} else {
				ToastUtil.show(UpPictures3Activity.this, R.string.no_result);
			}
		} else if (rCode == 27) {
			ToastUtil.show(UpPictures3Activity.this, R.string.error_network);
		} else if (rCode == 32) {
			ToastUtil.show(UpPictures3Activity.this, R.string.error_key);
		} else {
			ToastUtil.show(UpPictures3Activity.this,
					getString(R.string.error_other) + rCode);
		}
	}

	// /**
	// * 逆地理编码回调
	// */
	@Override
	public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
		// // TODO Auto-generated method stub
		dismissDialog();
		if (rCode == 0) {
			if (result != null && result.getRegeocodeAddress() != null
					&& result.getRegeocodeAddress().getFormatAddress() != null) {
				addressName = result.getRegeocodeAddress().getFormatAddress();
				result.getRegeocodeQuery().getPoint().getLatitude();
				attribute.setAddress_jingdu(""
						+ result.getRegeocodeQuery().getPoint().getLatitude());
				attribute.setAddress_jingdu(""
						+ result.getRegeocodeQuery().getPoint().getLongitude());
				// GeocodeAddress address =
				// result.getGeocodeAddressList().get(0);
				if (addressName != ""
						&& searchText.getText().toString().trim() != "") {
					searchText.setText(""
							+ result.getRegeocodeAddress().getFormatAddress());
				}
				// aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
				// AMapUtil.convertToLatLng(latLonPoint), 15));
				attribute.setAbsolute_address(addressName);
				attribute.setCity_name(result.getRegeocodeAddress().getCity());
				regeoMarker.setPosition(AMapUtil.convertToLatLng(latLonPoint));
				ToastUtil.show(UpPictures3Activity.this, addressName);
			} else {
				ToastUtil.show(UpPictures3Activity.this, R.string.no_result);
			}
		} else if (rCode == 27) {
			ToastUtil.show(UpPictures3Activity.this, R.string.error_network);
		} else if (rCode == 32) {
			ToastUtil.show(UpPictures3Activity.this, R.string.error_key);
		} else {
			ToastUtil.show(UpPictures3Activity.this,
					getString(R.string.error_other) + rCode);
		}
	}

	/**
	 * 隐藏进度条对话框
	 */
	public void dismissDialog() {
		if (progDialog != null) {
			progDialog.dismiss();
		}
	}

	/**
	 * 定位成功后回调函数
	 */
	@Override
	public void onLocationChanged(AMapLocation aLocation) {
		//    
		if (mListener != null && aLocation != null) {

			//    
			// "aLocation.getLatitude()--->"+aLocation.getLatitude()+"  aLocation.getLongitude()===>"+aLocation.getLongitude());
			mListener.onLocationChanged(aLocation);// 显示系统小蓝点

			// geoPoint=new GeoPoint((int) (aLocation.getLatitude() * 1E6),
			// (int) (aLocation.getLongitude() * 1E6));
			// //用给定的经纬度构造一个GeoPoint，单位是微度 (度 * 1E6)
			// CameraUpdateFactory a=CameraUpdateFactory.newLatLngZoom(new
			// LatLng(arg0, arg1), arg1)

			if (isFirstCallBack == true) {
				aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
						aLocation.getLatitude(), aLocation.getLongitude()), 12));// 设置指定的可视区域地图
				isFirstCallBack = false;
				latLonPoint = new LatLonPoint(aLocation.getLatitude(),
						aLocation.getLongitude());
				getAddress(new LatLonPoint(aLocation.getLatitude(),
						aLocation.getLongitude()));
//				   
//						+ "我是纬度==》" + latLonPoint.getLatitude());
				attribute.setAddress_jingdu("" + latLonPoint.getLongitude());
				attribute.setAddress_weidu("" + latLonPoint.getLatitude());
			}
		}
	}

	/**
	 * 激活定位
	 */
	@Override
	public void activate(OnLocationChangedListener listener) {
		mListener = listener;
		if (mAMapLocationManager == null) {
			mAMapLocationManager = LocationManagerProxy.getInstance(this);
			/*
			 * mAMapLocManager.setGpsEnable(false);
			 * 1.0.2版本新增方法，设置true表示混合定位中包含gps定位，false表示纯网络定位，默认是true Location
			 * API定位采用GPS和网络混合定位方式
			 * ，第一个参数是定位provider，第二个参数时间最短是2000毫秒，第三个参数距离间隔单位是米，第四个参数是定位监听者
			 */
			mAMapLocationManager.requestLocationUpdates(
					LocationProviderProxy.AMapNetwork, 2000, 10, this);
		}
	}

	/**
	 * 停止定位
	 */
	@Override
	public void deactivate() {
		mListener = null;
		if (mAMapLocationManager != null) {
			mAMapLocationManager.removeUpdates(this);
			mAMapLocationManager.destory();
		}
		mAMapLocationManager = null;
	}

	/**
	 * 显示进度条对话框
	 */
	public void showDialog() {
		progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progDialog.setIndeterminate(false);
		progDialog.setCancelable(true);
		progDialog.setMessage(getResources().getString(R.string.l_xb63));
		progDialog.show();
	}

	/**
	 * 响应逆地理编码
	 */
	public void getAddress(final LatLonPoint latLonPoint) {
		showDialog();
		RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,
				GeocodeSearch.AMAP);// 第一个参数表示一个Latlng，第二参数表示范围多少米，第三个参数表示是火系坐标系还是GPS原生坐标系
		geocoderSearch.getFromLocationAsyn(query);// 设置同步逆地理编码请求
	}

	/**
	 * 响应地理编码
	 */
	public void getLatlon(final String name) {
		showDialog();
		GeocodeQuery query = new GeocodeQuery(name, null);// 第一个参数表示地址，第二个参数表示查询城市，中文或者中文全拼，citycode、adcode，
		geocoderSearch.getFromLocationNameAsyn(query);// 设置同步地理编码请求
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.up_pictures_dingwei:
			// getAddress();
			getLatlon("" + searchText.getText().toString().trim());
			break;
		}
	}

	private class Friend_Item_Adapter extends BaseAdapter {
		private Context context;

		public Friend_Item_Adapter(Context context) {
			this.context = context;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return listObj_main.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return listObj_main.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(final int arg0, View arg1, ViewGroup arg2) {
			LayoutInflater inflater = LayoutInflater.from(context);
			arg1 = inflater.inflate(R.layout.friends_gallery_item, null);
			// if (!listObj_main.get(arg0).isJudge()) {
			// arg1.setVisibility(View.GONE);
			// } else {
			// arg1.setVisibility(View.VISIBLE);
			// }
			TextView gallery_item_text = (TextView) arg1
					.findViewById(R.id.gallery_item_text);
			ImageView gallery_item_cha = (ImageView) arg1
					.findViewById(R.id.gallery_item_cha);
			gallery_item_text.setText("@"
					+ listObj_main.get(arg0).getNickName());
			gallery_item_cha.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg10) {
					listObj_main.remove(arg0);
					Friend_Item_Adapter.this.notifyDataSetChanged();
				}
			});
			return arg1;
		}

	}

}
